/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import Data.Member;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author NGOCLINH-PC
 */
public class MemberPR extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            if (request.getParameter("txtcateid") != null) {
                int id = Integer.parseInt(request.getParameter("txtcateid"));
                int role = Integer.parseInt(request.getParameter("txtrole"));
                int stt = Integer.parseInt(request.getParameter("radio1"));

                int About = 1;
                int Event = 1;
                int Subcriber = 1;
                // int Contact = 1;
                int Category = 1;
                int Comment = 1;
                int Enroll = 1;
                int Prize = 1;
                //int PrizeType = 1;
                /// int Payment = 1;
                // int RoleType = 1;
                int txtMember = 1;
                int txtCustomer = 1;
                if (request.getParameter("About") != null) {
                    About = Integer.parseInt(request.getParameter("About"));
                }
                if (request.getParameter("Event") != null) {
                    Event = Integer.parseInt(request.getParameter("Event"));
                }
                if (request.getParameter("Subcriber") != null) {
                    Subcriber = Integer.parseInt(request.getParameter("Subcriber"));
                }

                if (request.getParameter("Category") != null) {
                    Category = Integer.parseInt(request.getParameter("Category"));
                }
                if (request.getParameter("Comment") != null) {
                    Comment = Integer.parseInt(request.getParameter("Comment"));
                }
                if (request.getParameter("Enroll") != null) {
                    Enroll = Integer.parseInt(request.getParameter("Enroll"));
                }
                if (request.getParameter("Prize") != null) {
                    Prize = Integer.parseInt(request.getParameter("Prize"));
                }

                if (request.getParameter("txtMember") != null) {
                    txtMember = Integer.parseInt(request.getParameter("txtMember"));
                }

                if (request.getParameter("txtCustomer") != null) {
                    txtCustomer = Integer.parseInt(request.getParameter("txtCustomer"));
                }

                int job = About * Event * Subcriber * Category * Comment * Enroll * Prize * txtMember * txtCustomer;
                //  out.print(job);
                Member.Mupdate(id, role, job, stt);
                out.print("<script>alert('Update Susccessful!');window.location.replace('admin/index.jsp?page=Member');</script>");

            } else if (request.getParameter("txtcustomer") != null) {
                int id = Integer.parseInt(request.getParameter("txtcustomer"));
                int role = Integer.parseInt(request.getParameter("txtrole"));
                int stt = Integer.parseInt(request.getParameter("radio1"));
                int job = 1;
                Member.Mupdate(id, role, job, stt);
                out.print("<script>alert('Update Susccessful!');window.location.replace('admin/index.jsp?page=Customers');</script>");

            } else if (request.getParameter("txtmemberid") != null) {
                int id = Integer.parseInt(request.getParameter("txtmemberid"));
                String name = request.getParameter("txtname");
                String pass = request.getParameter("txtPass");
                String email = request.getParameter("txtemail");
                String phone = request.getParameter("txtphone");
                String gender = request.getParameter("txtgender");
                String address = request.getParameter("txtaddress");
                String birthday = request.getParameter("txtbrithday");
                Member.MupdateProfile(id, name, pass, email, phone, gender, address, birthday);
                out.print("<script>alert('Update Susccessful!');window.location.replace('admin/index.jsp');</script>");

            } else if (request.getParameter("txtMemcl") != null) {
                int id = Integer.parseInt(request.getParameter("txtMemcl"));
                String name = request.getParameter("txtFullnamecl");
                String email = request.getParameter("txtEmailcl");
                String phone = request.getParameter("txtPhonecl");
                String gender = request.getParameter("txtgendercl");
                String address = request.getParameter("txtAddresscl");
                String birthday = request.getParameter("txtBirthdaycl");
               Member.MupdateProfilecl(id, name, email, phone, gender, address, birthday);
                out.print("<script>alert('Update Susccessful!');window.location.replace('client/index.jsp');</script>");
            } else {
                int idpay = Integer.parseInt(request.getParameter("AmemID"));
                Member.Mdelete(idpay);
                response.sendRedirect("/nlpp/admin/index.jsp?page=Member");
            }
            //response.sendRedirect("/nlpp/admin/index.jsp?page=Member");
        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
